<?php
class PeopleBlock extends BlockInstance {
	public $CI;
	
	function __construct()
	{
		$this->CI =& get_instance();
	}
	
	function __call($m, $a)
	{
		global $BBX;
		if (preg_match('/[a-z]+_([a-z]+)/', $m, $matches))
		{
			if ($matches[1] == 'content')
			{
				$content = $a[1];
				$data 	 = array(
					'block_instance' => $a[0],
					'people'		 => $this->CI->db->query('select users.* from users
						where users.id in (select engagements.user_id from engagements where engagements.content_id = ?)', array($content->id)),
					'bricabox'		 => $BBX['bricabox'],	// pass anyway so handle_proxy() can recreate the view via ajax
					'content'		 => $content			// pass anyway so handle_proxy() can recreate the view via ajax
				);
				$this->CI->load->view('blocks/people/block', $data);
			}
			elseif ($matches[1] == 'homepage')
			{
				$data = array(
					'bricabox'		 => $BBX['bricabox'],	// pass anyway so handle_proxy() can recreate the view via ajax
					'block_instance' => $a[0],
					//'people'		 => $this->CI->db->query('select users.* from users
					//	where users.id in (select engagements.user_id from engagements where engagements.content_id in
					//		(select contents.id from contents where contents.bricabox_id = ?))', array($BBX['bricabox']->id))
					'people'		 => $this->CI->db->query('select users.* from users
						where users.id in (select memberships.user_id from memberships where memberships.bricabox_id = ?)
					order by RAND()', array($BBX['bricabox']->id))
				);
				$this->CI->load->view('blocks/people/block', $data);
			}
		}
	}
}
?>